package com.ruoyi.project.pms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.pms.domain.PmsComment;
import com.ruoyi.db.pms.domain.query.PmsCommentQueryVo;
import com.ruoyi.project.pms.service.PmsCommentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品评论Controller
 *
 * @author ruoyi
 * @date 2020-04-20
 */
@Api(tags="pms管理：商品评论管理")
@RestController
@RequestMapping("/pms/comment")
public class PmsCommentController extends BaseController
{
    @Autowired
    private PmsCommentService pmsCommentService;

    @ApiOperation("查询商品评论列表")
    @PreAuthorize("@ss.hasPermi('pms:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsCommentQueryVo pmsCommentQueryVo)
    {
        startPage();
        List<PmsComment> list = pmsCommentService.selectPmsCommentList(pmsCommentQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出商品评论列表")
    @Log(title = "商品评论", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('pms:comment:export')")
    @GetMapping("/export")
    public AjaxResult export(PmsCommentQueryVo pmsCommentQueryVo)
    {
        List<PmsComment> list = pmsCommentService.selectPmsCommentList(pmsCommentQueryVo);
        ExcelUtil<PmsComment> util = new ExcelUtil<PmsComment>(PmsComment.class);
        return util.exportExcel(list, "comment");
    }

    @ApiOperation("获取商品评论详细信息")
    @Log(title = "商品评论", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('pms:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsCommentService.selectPmsCommentById(id));
    }

    @ApiOperation("新增商品评论")
    @Log(title = "商品评论", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('pms:comment:add')")
    @PostMapping
    public AjaxResult add(@RequestBody PmsComment pmsComment)
    {
        return toAjax(pmsCommentService.insertPmsComment(pmsComment));
    }

    @ApiOperation("新增商品评论回复")
    @Log(title = "商品评论回复", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('pms:comment:replyComment')")
    @PostMapping("/replyComment")
    public AjaxResult replyComment(@RequestBody PmsComment pmsComment)
    {
        return toAjax(pmsCommentService.insertPmsReplyComment(pmsComment));
    }

    @ApiOperation("修改商品评论")
    @Log(title = "商品评论", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('pms:comment:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody PmsComment pmsComment)
    {
        return toAjax(pmsCommentService.updatePmsComment(pmsComment));
    }

    @ApiOperation("删除商品评论")
    @Log(title = "商品评论", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('pms:comment:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsCommentService.deletePmsCommentByIds(ids));
    }
}
